package com.abel.bigwater.tlv.model

import com.alibaba.fastjson.JSON
import io.netty.buffer.Unpooled
import org.junit.Test
import org.slf4j.LoggerFactory

class TlvPlatformPacketTest {
    private val log = LoggerFactory.getLogger(TlvPlatformPacketTest::class.java)

    @Test
    fun testPack() {
        val p1 = TlvPlatformPacket()
        p1.body = TlvDevBody(command = TlvCmdType.T1Online.reply, dataList = ArrayList())

        val d1 = TlvData(tag = ResultCodeParam.TAG, resultCode = ResultCodeType.T1Bad.id)
        p1.body?.dataList?.add(d1)

        val buf = Unpooled.buffer()
        p1.fill(buf)

        log.info("platform packet: ${TlvHelper.toHexString(let {
            val ba = ByteArray(buf.readableBytes())
            buf.readBytes(ba)
            ba
        })}")
    }

    @Test
    fun testParseOnline() {
        val ba = TlvHelper.toByteArray("7b 2b 82 bb eb a2 51 46 75 f0 ba 8e 90 68 87 05")
        val p1 = TlvPlatformPacket()
        p1.parse(Unpooled.buffer().writeBytes(ba))

        log.info(JSON.toJSONString(p1, true))
    }
}